package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 目标:
 *
 * @author YUE
 * @date 2024/6/11 17:14
 */
@Mapper
public interface DishMapper {

    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user) values" +
            " (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @AutoFill(type = OperationType.INSERT)
    void inster(Dish dish);


    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    @Delete("delete from dish where id=#{id}")
    void deleteId(Long id);

    void update(Dish dish);

    /*
      根据分类id查询菜品
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> list(Dish dish);

    // 根据套餐id查菜品
    @Select("select d.* from dish d left join setmeal_dish s on d.id = s.dish_id where setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long id);
}